<?php

declare(strict_types=1);
namespace App\Controller\Api;

use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use App\Controller\AbstractController;
use Service\ConsumerService\PushUserGoodsMessageService;
use Service\Code\Normal;

/**
 * @Controller(prefix="/PushChannelMesage")
 * 推送渠道消息
 */
class PushChannelMesageController extends AbstractController
{
    /**
     * 接收渠道消息
     * 推送到队列
     * @RequestMapping(path="RevSelfBbcChannel", methods="POST")
     * @return string[]
     */
    public function selfBbcChannel(RequestInterface $request) 
    {
        try {
            $body = $request->getParsedBody();
            return PushUserGoodsMessageService::instance()->pushSelfBbcMessage((int)$body['cid'],$body['MessageType'],$body['data']);
        } catch ( \Throwable $th) {
            return Normal::returnCode(Normal::FAIL,"发布自营bbc渠道消息异常[{$th->getMessage()}]");
        }
    }
    
    /**
     * 接收三方渠道消息
     * 推送到队列
     * @RequestMapping(path="RevThirdpartyChannel", methods="POST")
     * @return string[]
     */
    public function RevThirdpartyChannel(RequestInterface $request)
    {
        try {
            $body = $request->getParsedBody();
            return PushUserGoodsMessageService::instance()->pushThirdBBCMessage($body['binfo'],$body['MessageType'],$body['data']);
        }  catch ( \Throwable $th) {
            return Normal::returnCode(Normal::FAIL,"推送三方渠道消息异常[{$th->getMessage()}]");
        }
    }
}
